package _14并发工具类_CountDownLatch;

import java.util.Random;
import java.util.concurrent.CountDownLatch;

public class Children extends Thread{
    private CountDownLatch latch;

    public Children(String name, CountDownLatch latch) {
        super(name);
        this.latch = latch;
    }

    @Override
    public void run() {
        String name = Thread.currentThread().getName();

        Random r = new Random();
        int time = r.nextInt(5)+1;//随机1-5秒的数字
        try {
            Thread.sleep(time*1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(name+"吃完饺子了"+time);
        latch.countDown();
    }
}
